use rand::Rng;
use std::cmp::Ordering;
use std::io;
fn main() {
    println!("猜数游戏!");
    // loop {
    println!("猜测一个数!");
    // let int_number = rand::thread_rng().gen_range(1..101);
    let int_number = rand::thread_rng().gen_range(1..=101);
    println!("神秘数字是：{}", int_number);
    let mut guess = String::new();
    // std::io::stdin().read_line (&mut guess).expect("无法读取行");
    io::stdin().read_line(&mut guess).expect("无法读取行");
    let guess: u32 = guess.trim().parse().expect("类型错误");
    /*     let guess: u32 = match guess.trim().parse() {
        Ok(num) => num,
        Err(_) => continue,
    }; */

    println!("你猜测的数是：{}", guess);
    match guess.cmp(&int_number) {
        Ordering::Less => println!("too small!"),
        Ordering::Equal => {
            println!("you win and the game is over! ");
            // break;
        }
        Ordering::Greater => print!("too big!"),
    }
    // }
}
